package com.code.day19;

import java.util.Collection;
import java.util.HashMap;

public class Demo01HashMap {
    public static void main(String[] args) {
        HashMap<String, String> map1 = new HashMap<>();
        // put 添加元素
        map1.put("name", "李四");
        map1.put("age", "18");
        map1.put("sex", "男");
        System.out.println(map1);
        System.out.println("===================================");
        // V remove(Object key)  ->;根据key删除键值对,返回的是被删除的value
        String remove = map1.remove("sex");
        System.out.println(remove);
        System.out.println(map1);
        System.out.println("===================================");
        // V get(Object key) ->; 根据key获取value
        String value = map1.get("郭靖");
        System.out.println("value = " + value);
        System.out.println("===================================");
        //boolean containsKey(Object key)  ->; 判断集合中是否包含指定的key
        boolean containsKey = map1.containsKey("郭靖");
        System.out.println("containsKey = " + containsKey);
        System.out.println("===================================");
        //Collection<V> values() ->; 获取集合中所有的value,转存到Collection集合中
        Collection<String> collection = map1.values();
        for (String s : collection) {
            System.out.println("s = " + s);

        }
    }

}
